<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/

if (!defined ('EXPLAY')) exit;

if (!is_registered ()) CORE::body_replace ($replace, Templater::display ('users/login_form.tpl'));
if (is_registered ()) {

	$new_mes_ = $db->query ("SELECT COUNT(mes_id) AS cnt FROM ".DB_PEREFIX."_messages WHERE mes_user = '".User::$properties['user_id']."' && mes_read = 'new'");
	$new_mes_ = $db->fetch_array ($new_mes_);
	$new_mes = $new_mes_['cnt'];
	
	if (file_exists ($_SERVER['DOCUMENT_ROOT'].'/images/avatars/'.User::$properties['user_id'].'.jpg'))
		$avatar = '/images/avatars/'.User::$properties['user_id'].'.jpg';
	else
		$avatar = '/images/avatars/noavatar.jpg';
	
	if ($new_mes == 0)
		$new_mes = 'У вас нет новых <a href="/messages/">сообщений</a>.';
	elseif ($new_mes == 1)
		$new_mes = '<a href="/messages/"><strong>У вас одно новое сообщение!</strong></a>';
	elseif ($new_mes == 2)
		$new_mes = '<a href="/messages/"><strong>У вас два новых сообщения!</strong></a>';
	elseif ($new_mes == 3)
		$new_mes = '<a href="/messages/"><strong>У вас три новых сообщения!</strong></a>';
	else
		$new_mes = '<a href="/messages/">Новых сообщений: <strong>'.$new_mes.'</strong></a>';
	
	$info = array ();
	$info['user_name'] = User::$properties['user_name'];
	$info['user_id'] = User::$properties['user_id'];
	$info['user_login'] = User::$properties['user_login'];
	$info['avatar_src'] = $avatar;
	$info['messages'] = $new_mes;
	
	Templater::set_var ('info', $info);	
	CORE::body_replace ($replace, Templater::display ('users/block.tpl'));
}

